package com.luoqy.speedy;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.luoqy.speedy.common.FirstCreateBase;

@SpringBootApplication
@EnableCaching
@EnableScheduling//定时任务
@EnableAspectJAutoProxy//aop
@EnableConfigurationProperties(DataSourceProperties.class)
//@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@MapperScan({"com.luoqy.speedy.core.base.dao"})
public class SpeedyApplication {
	@Value("SPRING-BOOT-APPLITION")
	public static String appName;
	
	public static String[] args;
	public static ConfigurableApplicationContext context;
	public static void main(String[] args) {
		SpeedyApplication.args=args;
		SpeedyApplication.context=SpringApplication.run(SpeedyApplication.class, args);
		/*FirstCreateBase.initBase(new HashMap<String,String>());*/
		boolean initFlag=FirstCreateBase.init();
		if(initFlag){
			System.err.println("项目启动成功,初始化数据成功");
		}else{
			System.err.println("项目启动成功,但初始化数据失败，请手动进行初始化数据");
		}
		
	}
	/**
     * 解决同一时间只能一个定时任务执行的问题
     * */
    @Bean
    public TaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
        taskScheduler.setPoolSize(5);
        return taskScheduler;
    }
}
